package com.example.mybatisplus.controller;

import com.example.mybatisplus.params.StockParam;
import com.example.mybatisplus.pojo.ResponseVo;
import com.example.mybatisplus.pojo.StockInfo;
import com.example.mybatisplus.service.StockService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/stock")
public class StockController {

    @Resource
    private StockService stockService;
    /**
     * 保存单个
     *
     * @param stockInfo
     * @return
     */
    @PostMapping("/saveOne")
    public ResponseVo saveOne(@RequestBody StockInfo stockInfo) {
        return stockService.saveOne(stockInfo);
    }

    /**
     * 批量保存
     * @param stockInfoList
     * @return
     */
    @PostMapping("/saveBatch")
    public ResponseVo saveBatch(@RequestBody List<StockInfo> stockInfoList) {
        return stockService.saveBatch(stockInfoList);
    }

    /**
     * 更新单个
     * @param stockInfo
     * @return
     */
    @PostMapping("/updateOne")
    public ResponseVo updateOne(@RequestBody StockInfo stockInfo) {
        return stockService.updateOne(stockInfo);
    }

    /**
     * 批量更新
     *
     * @param stockInfoList
     * @return
     */
    @PostMapping("/updateBatch")
    public ResponseVo updateBatch(@RequestBody List<StockInfo> stockInfoList) {
        return stockService.updateBatch(stockInfoList);
    }

    /**
     * 分页查找
     *
     * @param pageNo 当前页
     * @param pageSize 每页记录数
     * @param stockParam 库存查询参数封装对象
     * @return
     */
    @PostMapping("/page/list/{pageNo}/{pageSize}")
    public ResponseVo pageListByCondition(@PathVariable("pageNo") int pageNo, @PathVariable("pageSize") int pageSize, @RequestBody StockParam stockParam) {

        return stockService.findPageByCondition(stockParam, pageNo, pageSize);

    }

    /**
     * 根据商品码查找商品库存数量
     *
     * @param goodCount
     * @return
     */
    @GetMapping("/goodCount")
    public ResponseVo findGoodCount(@RequestParam("goodCount") String goodCount) {
        return stockService.findCountByGoodCode(goodCount);
    }

    /**
     * 修改商品库存数量
     *
     * @param id
     * @param count
     * @return
     */
    @PostMapping("/update/count")
    public ResponseVo updateStockCountById(Long id, Integer count) {
        return stockService.updateStockCountById(id, count);
    }

}
